#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Author: suixin
# @Company: Aerospace Shenzhou Intelligent System Technology Co., Ltd
# @Site: https://user.qzone.qq.com/350606539/main
# @Date: 2023-09-01 16:40:47
# @Remark: Life is short, I use python！
# @Software: vscode

import dmPython

try:
    # 创建达梦数据库连接
    conn = dmPython.connect(user='CIGPROXYNS',
                            password='CIGPROXYNS',
                            server='10.166.33.110',
                            port=15210)
    
    # 创建数据库操作对象
    cursor = conn.cursor()
    # try:
    #     # 清空表，初始化测试环境
    #     cursor.execute('delete from T2')
    # except (dmPython.Error, Exception) as err:
    #     print(err)
    try:
        # 插入数据
        cursor.execute('''INSERT INTO CIGPROXY.A4_SYS_ACCOUNT_0722(ID, ACCOUNTNAME,ACCOUNT,DEFAULTUSER,PASSWORD,CREATE_DATE)
       SELECT SYS_GUID() ID,'测试数据112','测试123','ADMIN0','1234567895',SYSDATE''')
        print('python: insert success!')

        # # 更新数据
        # cursor.execute("update DMHR.EMPLOYEE set EMPLOYEE_NAME = '刘强东' where EMPLOYEE_ID = 1157")
        # print('python: update success!')

        # 查询数据
        cursor.execute("select * from CIGPROXY.A4_SYS_ACCOUNT_0722")
        res = cursor.fetchall()
        for tmp in res:
            for c1 in tmp:
                print(c1)
        print('python: select success!')

        # # 删除数据
        # cursor.execute("delete from DMHR.EMPLOYEE where EMPLOYEE_ID = 1157")
        # print('python: delete success!')
        
    except (dmPython.Error, Exception) as err1:
        print(err1)
    conn.close()
except (dmPython.Error, Exception) as err:
    print(err)